{extend name="public/base" /} {block name="style"}
<link href="__CSS__/cash.css" rel="stylesheet">
<style>
	.s_active {
		background-color: #0D8DDB;
		color: #fff;
		font-size: 14px;
	}
	
	.m_input {
		width: 50px!important;
		text-align: center;
		height: 30px;
		border: 1px solid #EEE;
		-webkit-border-radius: 0!important;
		-moz-border-radius: 0!important;
		border-radius: 0!important;
		line-height: 28px!important;
	}
	
	.sk_table tr td {
		border: 1px #e7eaec solid;
		height: 40px;
		line-height: 40px;
		text-align: center;
	}
</style>
{/block} {block name="body"}
<div class=" gray-bg" data-scroll="y" data-scroll-destroy="true" id="container" scroll="true">
	<div id="dd_box" class="ibox-content" style="width:63%;height:650px;float: left;margin-top: 20px;">
		<div class="input-group m-b" style="margin:0;padding:0;border-bottom: 1px #C1C1C1 solid;width: 100%;">
			<p class="btn_ppp">
				<button type="button" data-id=0 class="ppbtn btn btn-outline btn-info">全部分类</button> {foreach name="tabletypes" id="tp"}
				<button type="button" data-id="{$tp.id}" class="ppbtn btn btn-outline btn-info">{$tp.type_name}</button> {/foreach}
			</p>
		</div>
		<div class="">
			<ul class="nav hs_nav pay_method pay_method1">
				{foreach name="houses" id="hou"}
				<li id="hou_li_{$hou.id}" data-id="{$hou.id}" class=" {if condition='$hou.status==2'} room-oepn {/if}">
					<p style="padding-top:30px;font-size: 16px;color: #2B303A;font-weight: 600;"><span>{$hou.table_name}</span></p>
					<p style="padding-top:10px;font-size: 16px;"><span>{$hou.scope_limit}人</span></p>
				</li>
				{/foreach}
			</ul>
		</div>
	</div>
	<div id="h_detail" class="ibox-content" style="position:relative;width:36%;height:650px;display:inline-block;margin-top: 20px;margin-left: 2px;">
		<div id="detail_info" style="display: none;">
			<div class="  animated fadeInRight">
				<div class="input-group m-b" style="width:100%;text-align: center;">
					<p> <span class="b_rs_pan" style="font-size: 24px;float: left;">金额:&nbsp;&nbsp;&nbsp;</span><span style="float: left;color: red;">￥<span id="total_price1" style="color: red;" class="b_rs_pan">0</span></span>
					</p>
					<p>开台时间:<span id="kt_time"></span></p>
				</div>
			</div>
			<table class="table  table-hover tcash">
				<thead>
					<tr class="long-tr text-center">
						<th>名称</th>
						<th>单价</th>
						<th>数量</th>
						<th>小计</th>
						<th>操作</th>
					</tr>
				</thead>
			</table>
			<div style="overflow-y: scroll;height: 400px;">
				<table class="table table-bordered table-hover">
					<tbody id="goods_cart1" class=" text-center">

					</tbody>
				</table>
			</div>
			<div class="row" style="width:100%;position: absolute;bottom: 100px;">
				<button onclick="guantai()" type="button" class="btn btn-white" style="width: 18%;">关台</button>&nbsp;&nbsp;
				<button onclick="diandan()" type="button" class="btn btn-white" style="width: 18%;">点单</button>&nbsp;&nbsp;
				<button onclick="zhuangtai()" type="button" class="btn btn-white" style="width: 18%;">转台</button>&nbsp;&nbsp;
				<button type="button" class="btn btn-white" style="width: 18%;" onclick="reset_gd()">清空</button>&nbsp;&nbsp;
				<button type="button" class="btn btn-white" style="width: 18%;">打印</button>
			</div>
			<div class="row" style="width:100%;position: absolute;bottom: 40px;">
				<button class="btn btn-primary p-btn" style="background-color: #CA4440;width:99%" type="button" onclick="sk()">收款</button>
			</div>
		</div>
		<div id="no_detail" style="vertical-align: middle;height:100%;">
			<div class="middle-box text-center animated fadeInDown">
				<h2>未开台</h2>
				<div class="error-desc">
					<p> 该房间还未开台~</p>
					<p><button id="btn_open_house" type="button" class="btn btn-primary">开台</button></p>
				</div>
			</div>
		</div>
	</div>

</div>
<div class=" gray-bg" data-scroll="y" style="display: none;" data-scroll-destroy="true" id="container1" scroll="true">
	<div id="gd_box" class="ibox-content" style="width:60%;height:650px;float: left;margin-top: 20px;margin-left: 20px;">
		<div class="  animated fadeInRight">
			<div class="input-group m-b">
				<div class="input-group-btn">
					<button tabindex="-1" id="goods_type" class="btn btn-white s_active" type="button">商品分类</button>
					<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button" aria-expanded="false"><span class="caret"></span>
                    </button>
					<ul class="dropdown-menu">
						<li data-id="0" data-name="全部分类">
							<a>全部分类</a>
							{foreach name="types" id="tp"}
							<li data-id="{$tp.id}" data-name="{$tp.name}">
								<a>{$tp.name}</a>
							</li>
							{/foreach}
					</ul>
				</div>
				<div class="input-group-btn">
					<button tabindex="-1" onclick="change_box(this,'pk_box','gd_box')" class="btn btn-white" type="button">商品套餐</button>
				</div>
				<input type="text" id="skey" class="form-control" placeholder="搜索商品编号或名称">
				<span class="input-group-addon"> <img  onclick="get_goods_list(null);" src="__IMG__/search.png" /></span>
			</div>
		</div>
		<table class="table  table-hover ">
			<thead>
				<tr class="long-tr text-center">
					<th>商品编号</th>
					<th>名称</th>
					<th>库存</th>
					<th>单价</th>
					<th>单位</th>
					<th>操作</th>
				</tr>
			</thead>
		</table>
		<div style="overflow-y: scroll;height: 500px;">
			<table class="table table-bordered table-hover">
				<tbody id="goods_list" class=" text-center">
					{volist name="goods" id='gd'}
					<tr>
						<td>{$gd.goods_no}</td>
						<td>{$gd.goods_name}</td>
						<td>{$gd.stock}</td>
						<td>{$gd.sale_price}</td>
						<td>{$gd.unit}</td>
						<td><span data-price="{$gd.sale_price}" data-stock="{$gd.stock}" data-id="{$gd.id}" data-no="{$gd.goods_no}" data-name="{$gd.goods_name}" style="font-size: 24px" onclick="select_goods(this,1)">+</span></td>
					</tr>
					{/volist}
				</tbody>
			</table>
		</div>
	</div>
	<div id="pk_box" class="ibox-content" style="display:none;width:60%;height:650px;float: left;margin-top: 20px;margin-left: 20px;">
		<div class="  animated fadeInRight">
			<div class="input-group m-b">
				<div class="input-group-btn">
					<button tabindex="-1" onclick="change_box(this,'gd_box','pk_box')" class="btn btn-white " type="button">商品分类</button>
					<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button" aria-expanded="false"><span class="caret"></span>
	                    </button>
					<ul class="dropdown-menu">
						{foreach name="types" id="tp"}
						<li>
							<a>{$tp.name}</a>
						</li>
						{/foreach}
					</ul>
				</div>
				<div class="input-group-btn">
					<button tabindex="-1" class="btn btn-white s_active" type="button">商品套餐</button>
				</div>
				<input type="text" class="form-control" placeholder="搜索套餐编号或名称">
				<span class="input-group-addon"> <img src="__IMG__/search.png" /></span>
			</div>
		</div>
		<table class="table  table-hover ">
			<thead>
				<tr class="long-tr text-center">
					<th>套餐编号</th>
					<th>名称</th>
					<th>单价</th>
					<th>单位</th>
					<th>操作</th>
				</tr>
			</thead>
		</table>
		<div style="overflow-y: scroll;height: 500px;">
			<table class="table  table-hover">
				<tbody id="list" class=" text-center">
					{volist name="packges" id='pk'}
					<tr id="pk_{$pk.id}">
						<td>{$pk.package_no}</td>
						<td>{$pk.package_name}</td>
						<td>{$pk.package_price}</td>
						<td>{$pk.unit}</td>
						<td><span data-goods="{$pk.goods_names}" data-name="{$pk.package_name}" data-price="{$pk.package_price}" data-no="{$pk.package_no}" data-id="{$pk.id}" style="font-size: 24px" onclick="select_goods(this,2)">+</span></td>
					</tr>
					{/volist}
				</tbody>
			</table>
		</div>
	</div>

	<div class="ibox-content" style="position:relative;width:36%;height:650px;display:inline-block;margin-top: 20px;margin-left: 2px;">
		<div>
			<div class="  animated fadeInRight">
				<div class="input-group m-b" style="width:100%;text-align: center;">
					<span class="b_rs_pan" style="font-size: 24px;float: left;">金额:&nbsp;&nbsp;&nbsp;</span><span style="float: left;color: red;">￥<span id="total_price" style="color: red;" class="b_rs_pan">0</span></span> <span class="b_rs_pan">商品/套餐列表</span>
				</div>
			</div>
			<table class="table  table-hover ">
				<thead>
					<tr class="long-tr text-center">
						<th>名称</th>
						<th>单价</th>
						<th>数量</th>
						<th>小计</th>
						<th>操作</th>
					</tr>
				</thead>
			</table>
			<div style="overflow-y: scroll;height: 400px;">
				<table class="table table-bordered table-hover">
					<tbody id="goods_cart" class=" text-center">

					</tbody>
				</table>
			</div>
			<div class="row" style="width:100%;position: absolute;bottom: 100px;">

			</div>
			<div class="row" style="width:100%;position: absolute;bottom: 40px;">
				<span style="float: right;">
			    <button class="btn btn-primary p-btn" style="background-color: #CA4440;" type="button" onclick="qd()">确定</button>
			    <button class="btn btn-white p-btn" onclick="back_up()" type="button" >返回</button>
				</span>
			</div>
		</div>
	</div>

</div>

<div class=" gray-bg" data-scroll="y" data-scroll-destroy="true" id="container2" style="display: none;" scroll="true">
	<div class="ibox float-e-margins" style="width:47%;float: left;margin-top: 20px;margin-left: 20px;">
		<div class="wrapper wrapper-content animated fadeInRight">
			<div class="row">
				<div class="input-group m-b">
					<input type="text" id="key" name="key" class="form-control" placeholder="搜索会员卡号/手机号/姓名">
					<span class="input-group-addon"> <img src="__IMG__/search.png" /></span>
					<span class="input-group-addon" onclick="adduser()"><img src="__IMG__/adduser.png" /></span>
				</div>
			</div>
			<div id="member_info" style="display: none;">
				<p><span class="m_rs_pan ">会员卡号:</span><span id="no"></span><span class="card_type">王者(无折扣)</span></p>
				<p><span class="m_rs_pan ">姓名:<span id="name"></span></span>
					<span class="m_rs_pan r1">手机号:<span id="mobile"></span></span>
					<span class="m_rs_pan r1">余额:<span id="money"></span></span>
					<span class="m_rs_pan r1">积分:<span id="score"></span></span>
				</p>
			</div>
			<div class="row line"></div>
			<div class="row">
				<div class="input-group m-b" style="width: 100%;">
					<span class="rs_pan">账单金额<span class="m_rs_pan">(元)</span></span>
					<input onkeyup="keyup_price(this)" readonly="readonly" type="text" id="price" class="form-control rs_input" placeholder="0.00￥">
				</div>
			</div>
			<div class="row line"></div>
			<div class="row">
				<div class="input-group m-b" style="width: 100%;">
					<span class="rs_pan">折后金额<span class="m_rs_pan">(元)</span></span>
					<input type="text" id="zhe_price" readonly="readonly" class="form-control rs_input" placeholder="">
				</div>
			</div>
			<div class="row line"></div>
			<div class="row">
				<div class="input-group m-b" style="width: 100%;">
					<span class="rs_pan">赠送积分</span>
					<input type="text" id="zs_score" readonly="readonly" class="form-control rs_input" placeholder="">
				</div>
			</div>
			<div class="row line"></div>
			<div class="row">
				<div class="input-group m-b" style="width: 100%;">
					<span class="b_rs_pan">应收金额<span class="m_rs_pan">(元)</span></span>
					<input type="text" id="ys_money" readonly="readonly" class="form-control rs_input" placeholder="">
				</div>
			</div>
			<div class="row line"></div>
			<div class="row">
				<div class="input-group m-b" style="width: 100%;">
					<button onclick="search_emp()" tabindex="-1" class="btn btn-white" type="button"><i class="fa fa-plus"></i>选择导购</button>
					<br />
					<div id="emp_info" style="display: none;">
						<p><span class="m_rs_pan ">导购员工号:<span id="zno"></span></span>
							<span class="m_rs_pan r1">职务:<span id="zname"></span></span>
						</p>
					</div>
					<textarea id="ccomment" name="comment" style="height: 80px;width: 100%;" class="form-control" required="" placeholder="填写备注" aria-required="true"></textarea>
				</div>
			</div>
		</div>
	</div>
	<div style="width:47%;display:inline-block;float: left;margin-top: 40px;margin-left: 20px;background-color: #fff;">
		<div class="wrapper wrapper-content animated fadeInRight" style="padding-top: 5px;padding-left: 25px;">
			<div class="row">
				<div class="input-group m-b" style="width: 100%;margin-bottom: 3px;">
					<div style="float:left"><span class="b_rs_pan">支付方式?</span></div>
					<div style="float:right;margin-right: 30px;"> 找零:<span style="float:right;margin-right: 25px;" class="rs_pan" id="zhaoling"></span></div>
				</div>
			</div>
			<div class="row line" style="padding-bottom: 3px;"></div>
			<div class="">
				<ul class="nav pay_method">
					<li class="sku" onClick="switch_spec(this)" data="1">
						<p><img src="__IMG__/pay.png" /></p>
						<p><span class="p_name">现金</span></p>
						<s></s>
					</li>
					<li class="sku " onClick="switch_spec(this)" data="2">
						<p><img src="__IMG__/card.png" /></p>
						<p><span class="p_name">会员卡</span></p>
						<s></s>
					</li>
					<li class="sku" onClick="switch_spec(this)" data="3">
						<p><img src="__IMG__/weixin.png" /></p>
						<p><span class="p_name">微信</span></p>
						<s></s>
					</li>
					<li class="sku" onClick="switch_spec(this)" data="4">
						<p><img src="__IMG__/alipay.png" /></p>
						<p><span class="p_name">支付宝</span></p>
						<s></s>
					</li>
					<li class="sku" onClick="switch_spec(this)" data = "5">
					<p><img src="__IMG__/bank.png"/></p>
					<p><span class="p_name">银联</span></p>
					<s></s>
					</li>
					<li class="sku" onClick="switch_spec(this)">
						<p><img src="__IMG__/card.png" /></p>
						<p><span class="p_name">自定义</span></p>
						<s></s>
					</li>
				</ul>
			</div>
			<div class="row line" style="margin-top: 5px;"></div>
			<div class="row" style="margin-left: 10px;height:25px;line-height: 25px;">
				<div onclick="select_juan()" style="display: inline;"><i class="fa fa-plus"></i>优惠券</div>
				<div id="coupon_juan" style="display: inline-block;padding-left: 20px;"></div>
			</div>
			<div class="row line"></div>
			<div class="row">
				<div class="input-group m-b" style="width: 100%;">
					<span class="b_rs_pan">付款金额<span class="m_rs_pan">(元)</span></span>
					<input type="text" onkeyup="keyup_pay(this)" id="pay_money" class="form-control rs_input1 " placeholder="0.00￥">
				</div>
			</div>
			<div class="row line"></div>
			<div class="row" style="margin-left: 20px;">
				<button class="btn btn-primary p-btn" type="button" onclick="confirm_sk()">确定收款</button>
				<button class="btn btn-white p-btn" type="button" onclick="back_up()">返回</button>
			</div>
		</div>
		<input type="hidden" name="pay_method" id="pay_method" />
		<input type="hidden" name="dg_empno" id="dg_empno" />
		<input type="hidden" name="line_member_id" id="line_member_id" />
		<input type="hidden" name="orderId" id="orderId" />
	</div>
</div>
{/block} {block name="script"}
<script src="__JS__/cash.js"></script>
<script>
	var cartlist = {};
	house_click();

	function back_up() {
		$('#container').show();
		$('#container1').hide();
		$('#container2').hide();
		$(".sku-bo-blo").removeClass("sku-bo-blo");
		$("#zhaoling").text("0");
		$("#pay_money").val(0);
	}

	function house_click() {
		$(".hs_nav li").click(function() {
			$(".room-selected").removeClass("room-selected");
			var hid = $(this).attr("data-id");
			$(this).addClass("room-selected");
			$.ajax({
				type: "post",
				data: {
					id: hid
				},
				url: "get_house",
				success: function(data) {
					if(data.code == 200) {
						$("#detail_info").show("fast");
						$("#no_detail").hide();
						var order = data.data;
						var list = order.item;
						var html = '<input type="hidden" id="order_id" value="' + order.id + '"/>';
						for(var i = 0; i < list.length; i++) {
							var item = list[i];
							var id = item['id'];
							var oid = item['order_id'];
							var name = item['name'];
							var type = item['type'];
							var price = parseFloat(item['price']);
							var num = parseFloat(item['num']);
							var is_zs = item['is_zs'];
							var goods_names = "";
							var z_class = "";
							var t_class = "";
							if(is_zs == 1) {
								z_class = "zs_active";
								t_class = "zs_total";
							}
							if(type == 2) {
								goods_names = item.goods_name;
							}
							var tr = '<tr data-oid=' + oid + ' data-id="' + id + '" data-price=' + price + ' data-zs=' + is_zs + ' data-num=' + num + ' >' +
								'<td>' + name + '</br>' + goods_names + '</td>' +
								'<td>' + price + '</td>' +
								'<td><input   class="m_input" type="text" value=' + num + ' /></td>' +
								'<td class="' + t_class + '" id=zstotal_' + id + '>' + price * num + '</td>' +
								'<td style="font-size:16px;"><span class="zs_pan ' + z_class + '"  >赠</span>&nbsp;&nbsp;<span class="del_pan" >删</span></td>' +
								'</tr>';
							html += tr;
						}
						$("#kt_time").text(data.kt_time);
						$("#total_price1").text(order.price);
						$("#goods_cart1").html(html);
					} else if(data.code == 404) {
						//未开台
						$("#detail_info").hide();
						$("#no_detail").show("fast");
					} else {
						$("#kt_time").text(data.kt_time);
						//已开台未添加商品
						$("#detail_info").show("fast");
						$("#no_detail").hide();
						$("#total_price1").text(0);
						$("#goods_cart1").html("");
					}
					setEvent();
				}
			});
		})
	}
	var eve = 0; //判断多次点击
	function setEvent() {
		$("#goods_cart1 .m_input").change(function() {
			var tr = $(this).parent().parent();
			var id = tr.data("id");
			var order_id = tr.data("oid");
			var num = tr.attr("data-num");
			var new_num = $(this).val();
			var price = parseFloat(tr.data("price"));
			var is_zs = tr.data("zs");
			var change_price = (new_num - num) * price;
			$.ajax({
				type: "post",
				data: {
					item_id: id,
					num: new_num,
					order_id: order_id,
					change_price: change_price
				},
				url: "update_item",
				success: function(data) {
					if(data.code == 200) {
						tr.attr("data-num", new_num);
						$total_price = new_num * price;
						var total_price1 = parseFloat($("#total_price1").text());
						if(is_zs == 0) {
							total_price1 += change_price;
							$("#total_price1").text(total_price1);
						}
						$("#zstotal_" + id).text($total_price);
					} else {
						layer.msg("操作错误");
					}
				}
			})
		})
		$("#goods_cart1 .zs_pan").click(function() {
			if(eve == 1) {
				layer.msg("请勿频繁点击");
				return;
			}
			eve = 1;
			$(this).toggleClass("zs_active");
			var tr = $(this).parent().parent();
			var id = tr.data("id");
			$("#zstotal_" + id).toggleClass("zs_total");
			var order_id = tr.data("oid");
			var num = tr.data("num");
			var price = parseFloat(tr.data("price"));
			var is_zs = tr.attr("data-zs");
			if(is_zs == 0) {
				var change_price = -num * price;
			} else {
				var change_price = num * price;
			}
			var change_zs = is_zs == 0 ? 1 : 0;
			$.ajax({
				type: "post",
				data: {
					item_id: id,
					order_id: order_id,
					change_price: change_price,
					is_zs: change_zs
				},
				url: "update_item",
				success: function(data) {
					if(data.code == 200) {
						tr.attr("data-zs", change_zs);
						var total_price1 = parseFloat($("#total_price1").text());
						total_price1 += change_price;
						$("#total_price1").text(total_price1);
					} else {
						layer.msg("操作错误");
					}
					eve = 0;
				}
			})
		})
		$("#goods_cart1 .del_pan").click(function() {
			var obj = $(this);
			var con = layer.confirm('确定删除?', {
				icon: 3,
				title: '提示'
			}, function(index) {
				var tr = obj.parent().parent();
				var id = tr.data("id");
				var order_id = tr.data("oid");
				var num = tr.data("num");
				var price = parseFloat(tr.data("price"));
				var is_zs = tr.data("zs");
				var change_price = -num * price;
				if(is_zs==1){
					change_price=0;
				}
				$.ajax({
					type: "post",
					data: {
						item_id: id,
						order_id: order_id,
						change_price: change_price,
						is_zs:is_zs,						
						is_del: 1
					},
					url: "update_item",
					success: function(data) {
						if(data.code == 200) {
							var total_price1 = parseFloat($("#total_price1").text());
							if(is_zs == 0) {
								total_price1 += change_price;
								$("#total_price1").text(total_price1);
							}
							tr.remove();
						} else {
							layer.msg("操作错误");
						}
						layer.close(con);
					}
				})
			});
		})
		$("#goods_cart .m_input").change(function() {
			change_goods(this);
		})
		$("#goods_cart .zs_pan").unbind('click').click(function() {
			zs_goods(this);
		})
		$("#goods_cart .del_pan").unbind('click').click(function() {
			del_goods(this);
		})
	}
	$(".ppbtn").click(function() {
		var typeid = $(this).attr("data-id");
		$.ajax({
			type: "post",
			data: {
				typeid: typeid
			},
			url: "get_houses",
			success: function(data) {
				if(data.code == 200) {
					var list = data.data;
					var html = "";
					for(var i = 0; i < list.length; i++) {
						var table = list[i];
						var classr = "";
						if(table.status == 2) {
							classr = "room-oepn";
						}
						var li = '<li id="hou_li_' + table.id + '" data-id="' + table.id + '" class="' + classr + '" >' +
							'<p style="padding-top:30px;font-size: 16px;color: #2B303A;font-weight: 600;"><span >' + table.table_name + '</span></p>' +
							'<p style="padding-top:10px;font-size: 16px;"><span >' + table.scope_limit + '人</span></p>' +
							'</li>';
						html += li;
					}
					$(".hs_nav").html(html);
					house_click();
				} else {
					$(".hs_nav").html("该分类没有房台");
				}
			}
		})
	})

	function qd() {
		var gds = $("#goods_cart").html();
		var price = $("#total_price").text();
		var total_price = parseFloat($("#total_price1").text()) + parseFloat(price);
		var id = $(".room-selected").attr("data-id");
		var status = 1; //是否已经添加商品
		if(gds == "") {
			layer.msg("未添加商品或套餐!");
			return;
		}
		var order_id = $("#order_id").val();
		if(order_id == undefined) {
			if($("#goods_cart1").html().trim() == "") {
				status = 0;
			}
		}
		$.ajax({
			type: "post",
			data: {
				id: id,
				status: status,
				type: 3,
				data: cartlist,
				price: price
			},
			url: "add_house",
			success: function(data) {
				if(data.code == 200) {
					cartlist = {};
					$("#orderId").val(data.orderId);
					var html = "";
					var list = data.data;
					for(var i = 0; i < list.length; i++) {
						var item = list[i];
						var id = item['id'];
						var oid = item['order_id'];
						var name = item['name'];
						var type = item['type'];
						var price = parseFloat(item['price']);
						var num = parseFloat(item['num']);
						var is_zs = item['is_zs'];
						var goods_names = "";
						var z_class = "";
						var t_class = "";
						if(is_zs == 1) {
							z_class = "zs_active";
							t_class = "zs_total";
						}
						if(type == 2) {
							goods_names = item.goods_name;
						}
						var tr = '<tr data-oid=' + oid + ' data-id="' + id + '" data-price=' + price + ' data-zs=' + is_zs + ' data-num=' + num + ' >' +
							'<td>' + name + '</br>' + goods_names + '</td>' +
							'<td>' + price + '</td>' +
							'<td><input   class="m_input" type="text" value=' + num + ' /></td>' +
							'<td class="' + t_class + '" id=zstotal_' + id + '>' + price * num + '</td>' +
							'<td style="font-size:16px;"><span class="zs_pan ' + z_class + '" >赠</span>&nbsp;&nbsp;<span class="del_pan" >删</span></td>' +
							'</tr>';
						html += tr;
					}
					$("#total_price1").text(total_price);
					$("#total_price").text(0);
					$("#goods_cart1").html(html);
					setEvent();
					$("#goods_cart").html("");
					$("#container1").hide();
					$("#container").show();
				} else {
					layer.msg(data.msg);
				}
			}
		})
	}

	function diandan() {
		cartlist = {};
		$("#container").hide();
		$("#container1").show();
		$("#goods_cart").html("");
	}
	//转台 
	function zhuangtai() {
		$.ajax({
			type: "post",
			data: {
				status: 1
			},
			url: "get_houses",
			success: function(data) {
				if(data.code == 200) {
					var list = data.data;
					var html = '<ul class="nav zt_nav pay_method" >';
					for(var i = 0; i < list.length; i++) {
						var table = list[i];
						var li = '<li  data-id="' + table.id + '">' +
							'<p style="padding-top:30px;font-size: 16px;color: #2B303A;font-weight: 600;"><span >' + table.table_name + '</span></p>' +
							'<p style="padding-top:10px;font-size: 16px;"><span >' + table.scope_limit + '人</span></p>' +
							'</li>';
						html += li;
					}
					html += "</ul>";
					var index = layer.open({
						title: '转台',
						area: ['600px', '350px'],
						content: html,
						btn: ['确定', '取消'],
						yes: function(index, layero) {
							var id = $(".room-selected").attr("data-id"); //旧台
							var id1 = $(".room-selected1").attr("data-id"); //新台
							var status = 1; //是否已经添加商品
							if($("#goods_cart1").html().trim() == "") {
								status = 0;
							}
							if(id1 == undefined) {
								layer.msg("您未选择房台");
								return;
							}
							$.ajax({
								type: "post",
								data: {
									old_id: id,
									new_id: id1,
									status: status
								},
								url: "zhuantai",
								success: function(data) {
									if(data.code == 200) {
										$(".room-selected").removeClass("room-oepn");
										$(".room-selected").removeClass("room-selected");
										$(".room-selected1").removeClass("room-selected1");
										$("#hou_li_" + id1).addClass('room-selected');
										$("#hou_li_" + id1).addClass('room-oepn');
										layer.msg(data.msg);
									} else {
										layer.msg(data.msg);
									}
								}
							})
						},
						btn2: function(index, layero) {
							layer.close(index);
						}
					})
					ztclick();
				} else {
					layer.msg(data.msg);
				}
			}
		})
	}

	function ztclick() {
		$(".zt_nav li").click(function() {
			$(".room-selected1").removeClass("room-selected1");
			var id = $(this).attr("data-id");
			$(this).addClass("room-selected1");
		})
	}
	//关台
	function guantai() {
		var id = $(".room-selected").attr("data-id");
		if(id == undefined) {
			layer.msg("您未选择房台");
			return;
		}
		$.ajax({
			type: "post",
			data: {
				id: id,
				status: 1
			},
			url: "update_house",
			success: function(data) {
				if(data.code == 200) {
					$(".room-selected").removeClass("room-oepn");
					$("#detail_info").hide();
					$("#no_detail").show("fast");
					$("#goods_cart1").html("");
					$("#total_price1").html("0");
				} else {
					layer.msg(data.msg);
				}
			}
		})
	}
	$("#btn_open_house").click(function() {
		var id = $(".room-selected").attr("data-id");
		if(id == undefined) {
			layer.msg("请选择房台!");
			return;
		}
		$.ajax({
			type: "post",
			data: {
				id: id,
				status: 2
			},
			url: "update_house",
			success: function(data) {
				if(data.code == 200) {
					$("#hou_li_" + id).addClass("room-oepn");
					$("#no_detail").hide();
					$("#detail_info").show("fast");
				} else {
					layer.msg(data.msg);
				}
			}
		});

	})

	function sk() {
		if($("#goods_cart1").html().trim() == "") {
			layer.msg("您未添加任何商品");
			return false;
		}
		var price = $("#total_price1").text();
		$("#container").hide();
		$("#container1").hide();
		$("#container2").show();
		$("#price").val(price);
		$("#zs_score").val(price);
		$("#zhe_price").val(price);
		$("#ys_money").val(price);
	}

	//清空挂单
	function reset_gd() {
		cartlist = {};
		$("#total_price").text(0);
		$("#goods_cart").html("");
		$("#pay_money").html("");
		$(".sku-bo-blo").removeClass("sku-bo-blo");
		$("#detail_info").hide();
		$("#no_detail").show();
	}

	function del_order(id) {
		layer.confirm('确定删除?', {
			icon: 3,
			title: '提示'
		}, function(index) {
			$.ajax({
				url: 'del_order',
				data: {
					"id": id
				},
				type: "post",
				success: function(data) {
					layer.msg("删除成功");
				}
			})

		});
	}
	$(".dropdown-menu li").click(function() {
		var goods_typeid = $(this).attr('data-id');
		$("#goods_type").text($(this).attr('data-name'));
		get_goods_list({
			'goods_typeid': goods_typeid
		});
	})

	function get_goods_list(dt) {
		if(dt == null) {
			var skey = $("#skey").val();
			dt = {
				'key': skey
			};
		}
		$.ajax({
			url: 'get_goods_list',
			data: dt,
			type: "post",
			success: function(data) {
				var html = "";
				var res = data.data;
				if(res == null) {
					return;
				}
				for(var i = 0; i < res.length; i++) {
					var gd = res[i];
					var tr = '<tr>' +
						'<td>' + gd.goods_no + '</td>' +
						'<td>' + gd.goods_name + '</td>' +
						'<td>' + gd.stock + '</td>' +
						'<td>' + gd.sale_price + '</td>' +
						'<td>' + gd.unit + '</td>' +
						'<td><span data-price="' + gd.sale_price + '" data-stock="' + gd.stock + '" data-id="' + gd.id + '" data-name="' + gd.goods_name + '" style="font-size: 24px" onclick="select_goods(this,1)">+</span></td>' +
						'</tr>';
					html += tr;
				}
				$("#goods_list").html(html);
			}
		})
	}

	function select_goods(obj, type) {
		var goods_names = "";
		var arr = {};
		if(type == 2) {
			goods_names = $(obj).attr("data-goods");
			arr['goods_names'] = goods_names;
		} else {
			arr['goods_names'] = "";
		}
		var id = $(obj).attr("data-id");
		var name = $(obj).attr("data-name");
		var price = parseFloat($(obj).attr("data-price"));
		var cart = cartlist[id + type];
		if(cart != null) {
			cartlist[id + type]['total_price'] = parseFloat(cartlist[id + type]['total_price']) + parseFloat(price);
			cartlist[id + type]['num'] = cartlist[id + type]['num'] + 1;
		} else {
			arr['type'] = type;
			arr['name'] = name;
			arr['price'] = price;
			arr['total_price'] = price;
			arr['num'] = 1;
			arr['sid'] = id;
			arr['is_zs'] = 0; //是否赠送
			cartlist[id + type] = arr;
		}
		var has = $("#goods_" + id + type);
		if(has.val() == undefined) {
			var html = '<tr>' +
				'<td>' + name + '</br>' + goods_names + '</td>' +
				'<td>' + price + '</td>' +
				'<td><input data-name=' + id + type + '  id=goods_' + id + type + '  class="m_input" type="text" value=1 /></td>' +
				'<td id=total_' + id + type + '>' + price + '</td>' +
				'<td data-name=' + id + type + ' style="font-size:16px;"><span data-name=' + id + type + ' class="zs_pan">赠</span>&nbsp;&nbsp;<span class="del_pan" data-name=' + id + type + ' >删</span></td>' +
				'</tr>';
			$("#goods_cart").append(html);
			setEvent();
		} else {
			has.val(parseFloat(has.val()) + 1);
			$("#total_" + id + type).text(parseFloat($("#total_" + id + type).text()) + parseFloat(price));
		}
		var total_price = parseFloat($("#total_price").text()) + parseFloat(price);
		$("#total_price").text(total_price);

	}
	/**
	 * 赠送商品
	 */
	function zs_goods(obj) {
		$(obj).toggleClass("zs_active");
		var ckey = $(obj).data("name");
		$("#total_" + ckey).toggleClass("zs_total");
		var is_zs = cartlist[ckey]["is_zs"];
		var total_price = parseFloat($("#total_price").text());
		if(is_zs == 1) {
			cartlist[ckey]["is_zs"] = 0;
			total_price += parseFloat(cartlist[ckey]['total_price']);
			$("#total_price").text(total_price);
		} else {
			total_price -= parseFloat(cartlist[ckey]['total_price']);
			$("#total_price").text(total_price);
			cartlist[ckey]["is_zs"] = 1;
		}
		//		$(obj).parent().parent().remove();
		//		layer.close(con);

	}
	/**
	 * 删除购物车商品
	 */
	function del_goods(obj) {
		var con = layer.confirm('确定删除?', function(index) {
			var total_price = parseFloat($("#total_price").text());
			var ckey = $(obj).data("name");
			var is_zs = cartlist[ckey]["is_zs"];
			if(is_zs == 0) {
				total_price -= parseFloat(cartlist[ckey]['total_price']);
				$("#total_price").text(total_price);
			}
			delete(cartlist[ckey]);
			$(obj).parent().parent().remove();
			layer.close(con);

		});

	}
	/**
	 * 改变商品数量
	 */
	function change_goods(obj) {
		var ckey = $(obj).data("name");
		var num = parseFloat($(obj).val());
		$total_price = num * cartlist[ckey]['price'];
		var total_price1 = parseFloat($("#total_price").text());
		var is_zs = cartlist[ckey]["is_zs"];
		if(is_zs == 0) {
			total_price1 += parseFloat($total_price - parseFloat(cartlist[ckey]['total_price']));
			$("#total_price").text(total_price1);
		}
		cartlist[ckey]['num'] = $(obj).val();
		cartlist[ckey]['total_price'] = $total_price;
		$("#total_" + ckey).text($total_price);
	}

	function change_box(obj, show, hidden) {
		$("#" + show).show();
		$("#" + hidden).hide();
	}



	function confirm_sk() {
		var price = $("#price").val();
		if(price == "" || isNaN(price)) {
			layer.msg("请输入正确的账单金额!");
			return false;
		}
		var pay_method = $("#pay_method").val();
		if(pay_method == "") {
			layer.msg("请选择支付方式!");
			return false;
		}
		var pay_money = $("#pay_money").val();
		if(pay_money == "" || isNaN(pay_money)) {
			layer.msg("请输入正确的付款金额!");
			return false;
		}
		if(parseFloat(pay_money) < parseFloat(price)) {
			layer.msg("付款金额小于账单金额!");
			return false;
		}
		if(pay_method == 2) {
			if($("#key").val() == "") {
				layer.msg("请输入正确的会员卡号!");
				return false;
			}
			var yue = parseFloat($("#money").text());
			if(yue < parseFloat(price)) {
				layer.msg("余额不足!");
				return false;
			}
		}
		var zhaoling = parseFloat($("#zhaoling").text());
		var html = '<div class="row" >' +
			'<div style="float: left;width:50%;text-align: center;">' +
			'<span id="sp_price" style="font-size:26px;font-weight:600;color:#35b12c">' + price + '</span>' +
			'<p>应收金额</p>' +
			'</div>' +
			'<div style="float: left;width:50%;text-align: center;">' +
			'<span id="sp_zhaoling" style="font-size:26px;font-weight:600;color:red">' + zhaoling + '</span>' +
			'<p>找零</p>' +
			'</div>' +
			'</div>' +
			'<div class="row" style="text-align: center;">' +
			'<p>收银员:godlike</p>' +
			'</div>';
		var house_id = $(".room-selected").attr("data-id");
		var coupon_id=$("#counpon_span").attr('data-id');
		if(coupon_id==undefined){
			coupon_id=0;			
		}
		var index = layer.open({
			title: '确认收款',
			zIndex :1999,
			area: ['500px', '250px'],
			content: html,
			btn: ['确定', '取消'],
			yes: function(index, layero) {
				//按钮【按钮一】的回调
				$.ajax({
					url: 'shoukuan',
					data: {
						orderId:$("#orderId").val(),
						coupon_id:coupon_id,
						house_id: house_id,
						pay_money: pay_money,
						price:price,
						type:4,
						zs_score:$("#zs_score").val(),
						zhaoling: zhaoling,
						pay_method: pay_method,
						dg_id: $("#dg_empno").val(),
						line_member_id: $("#line_member_id").val()
					},
					type: "post",
					success: function(dataa) {
						layer.close(index);
						if(pay_method==3||pay_method==4){
								var dt=dataa.data;
								if(pay_method==3){
									var ct='<div style="margin-left:100px;padding:0;"><img alt="扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data='+dt.code_url+'" style="width:200px;height:200px;"/><div>';
								}else{
									var ct='<div style="margin-left:100px;padding:0;"><img alt="扫码支付" src="'+dt.code_url+'" style="width:200px;height:200px;"/><div>';
								}
								var index1=layer.open({
							 	  area: ['450px', '350px'] ,
							 	  zIndex :1999,
							 	  title:"扫码支付",
								  content: ct,
								  btn: ['支付完成','取消'],
								  yes: function(index, layero){
									  		$.ajax({
									  			type:"post",
									  			url:"confirm_pay",
									  			data:{sn:dt.sn},
									  			success:function(data){
									  				if(data==1){
									  					callback(dataa);
														empty();
									  				}else{
									  					layer.msg("订单支付失败");
									  				}
									  			}
									  		});
								  },btn2:function(index,layero){
								  	layer.close(index1);
								  }
								});
							}else{
								callback(dataa);
							}
						
					}
				})
			},
			btn2: function(index, layero) {
				layer.close(index);
			}
		});

	}

	function callback(data) {
		if(data.code == 200) {
			$(".room-selected").removeClass("room-oepn");
			var info = data.data;
			var html = '<div>' +
				'<div style="text-align: center;">' +
				'<i class="fa fa-check" style="color: #35b12c;font-size: 60px;font-weight: 600;"></i>' +
				'<p><span class="b_rs_pan">收款成功</span> </p>' +
				'</div>' +
				'<div  style="text-align: center;"><span >单号</span><span style="margin-left: 50px;">' + info.sn + '</span></div>' +
				'<div  style="text-align: center;"><span >交易时间</span><span style="margin-left: 50px;">' + info.add_time + '</span></div>' +
				'<div  style="text-align: center;"><span >门店</span><span style="margin-left: 50px;">' + info.store_name + '</span></div>' +
				'<div  style="text-align: center;"><span >操作员</span><span style="margin-left: 50px;">' + info.skr + '</span></div>' +
				'</div>';
			var index = layer.open({
				title: '收款成功',
				zIndex :1999,
				area: ['600px', '350px'],
				content: html,
				btn: ['我知道了', '打印小票'],
				yes: function(index, layero) {
					layer.close(index);
					$("#container").show();
					$("#container1").hide();
					$("#container2").hide();
					$("#goods_cart1").html("");
					reset_gd();
				},
				btn2: function(index, layero) {
					layer.msg("打印成功");
					$("#container").show();
					$("#container1").hide();
					$("#container2").hide();
					reset_gd();
				}
			});

		} else {
			layer.msg(data.msg);
			window.reload();
		}

	}


	function call_back(msg) {
		layer.msg(msg);
		layer.closeAll('iframe');
	}

	
</script>
{/block}